local sx,sy = guiGetScreenSize()
local xres,yres = (sx/1920), (sy/1080)
czas = math.random(4000,9000)
local font = dxCreateFont( ":cmta-pobieraniezasobow/OSB.ttf",40*xres )
local font2 = dxCreateFont( ":cmta-pobieraniezasobow/OSB.ttf",20*xres )
local buttonbonus = false
loadstring(exports.dgs:dgsImportFunction())()

tabela={}

for i=1,48 do
    losowaliczba = math.random(0,10000)


if losowaliczba >= 0 and losowaliczba < 5000 then
    pole = "exp.png"
elseif losowaliczba >= 5000 and losowaliczba < 5005 then
    pole = "car.png"
elseif losowaliczba >= 5005 and losowaliczba < 8980 then
    pole = "point.png"
elseif losowaliczba >= 8980 and losowaliczba < 9830 then
    pole = "cigarette.png"
elseif losowaliczba >= 9830 and losowaliczba < 9955 then
    pole = "gun.png"
elseif losowaliczba >= 9955 then
    pole = "vip.png"
end
    table.insert(tabela,{i,pole})
end

start = getTickCount()
koniec= getTickCount()
ruletkapola = dxCreateRenderTarget(xres*800, yres*150, true)

function rollowanie()
if buttonbonus == true then
dxDrawText("#DD6B20Bonus dzienny", 360*xres*2, 220*yres, 1200*xres, 150*yres, tocolor(255, 9, 9, 255), 1,font, "center", "center", false, false, false, true, false)
dxDrawRoundedRectangle(xres*360, yres*280, xres*1200.0, yres*150,15,tocolor(0,0,0,220))
dxDrawRoundedRectangle(xres*360, yres*570, xres*1200.0, yres*210,15,tocolor(0,0,0,150))
dxDrawImage(xres*380, yres*580, xres*150, yres*150, "exp.png")
dxDrawImage(xres*580, yres*580, xres*150, yres*150, "point.png")
dxDrawImage(xres*780, yres*580, xres*150, yres*150, "cigarette.png")
dxDrawImage(xres*980, yres*580, xres*150, yres*150, "gun.png")
dxDrawImage(xres*1180, yres*580, xres*150, yres*150, "vip.png")
dxDrawImage(xres*1380, yres*580, xres*150, yres*150, "car.png")
dxDrawText("#DD6B2050%", xres*382*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)
dxDrawText("#DD6B2039.75%", xres*582*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)
dxDrawText("#DD6B208.5%", xres*782*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)
dxDrawText("#DD6B201.25%", xres*982*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)
dxDrawText("#DD6B200.45%", xres*1182*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)
dxDrawText("#DD6B200.05%", xres*1382*2, yres*670*2, xres*150, yres*150, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)

else
dxDrawRoundedRectangle(xres*360, yres*280, xres*1200.0, yres*150,15,tocolor(0,0,0,220))
dxDrawText("#DD6B20Bonus dzienny", 360*xres*2, 220*yres, 1200*xres, 150*yres, tocolor(255, 9, 9, 255), 1,font, "center", "center", false, false, false, true, false)
dxDrawText("#ffffffTrwa losowanie nagrody...\n#ff0000Nie opuszczaj gry!", 360*xres*2, 920*yres, 1200*xres, 150*yres, tocolor(255, 9, 9, 255), 1,font2, "center", "center", false, false, false, true, false)



local postep =  (getTickCount()- start)/(koniec- start)
przesuniecie = interpolateBetween(-15*70,0,0,yres*-random*150,0,0,postep ,'OutQuad')
x=70*6.21
dxSetRenderTarget()
dxSetRenderTarget(ruletkapola,true)
for i,v in ipairs(tabela) do
    dxDrawImage(xres*x+przesuniecie, yres*0, xres*150.0, yres*150, v[2])
    x=x+150
end
dxSetRenderTarget()
dxDrawImage(xres*360, yres*280, xres*1200.0, yres*150, ruletkapola)
dxDrawRectangle(xres*955, yres*280, xres*10, yres*150,tocolor(255, 0,0, 200))
end
end


addEvent("cmta_aktywujbonus", true)
addEventHandler("cmta_aktywujbonus", resourceRoot, function()
    buttonbonus = true
    addEventHandler("onClientRender", getRootElement(), rollowanie )
    showCursor(true)
    button = dgsCreateButton( 750*xres, 480*yres, 420*xres, 50*yres, "Losuj", false,false,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
    addEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
end)

function startroll()
	random = math.random(35,45)
    start = getTickCount()
    koniec = getTickCount()+czas
    setTimer(function()
        local nagroda = tabela[random][2]
        if nagroda == "exp.png" then
        local aexp = math.random(25,120)
        exports["cmta-systemleveli"]:giveexp(aexp,localPlayer)
        outputChatBox("#00ff00[BONUS DNIA] #808080Otrzymujesz #ff0000"..aexp.." punktów expa.",255,255,255,true)
        elseif nagroda == "point.png" then 
        triggerServerEvent("cmta_bonusdnia_nagroda",resourceRoot,"point")
        elseif nagroda == "cigarette.png" then 
        triggerServerEvent("cmta_bonusdnia_nagroda",resourceRoot,"cigarette")
        elseif nagroda == "gun.png" then 
        triggerServerEvent("cmta_bonusdnia_nagroda",resourceRoot,"gun")
        elseif nagroda == "vip.png" then 
        triggerServerEvent("cmta_bonusdnia_nagroda",resourceRoot,"vip")
        elseif nagroda == "car.png" then 
        triggerServerEvent("cmta_bonusdnia_nagroda",resourceRoot,"car")
        end
        setTimer(function()
            removeEventHandler("onClientRender", getRootElement(), rollowanie )
        end,3000,1)
    end,czas,1)
end

function onclick ( btn, state )
    if btn == "left" and state == "down" and buttonbonus == true then
        if source == button then
            destroyElement(button)
            buttonbonus = false
            removeEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
            showCursor(false)
            startroll()
            triggerServerEvent("cmta_bonusdnia_nalicz",resourceRoot)
        end
    end
end

function dxDrawRoundedRectangle(x, y, width, height, radius, color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y+radius, width-(radius*2), height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawCircle(x+radius, y+radius, radius, 180, 270, color, color, 16, 1, postGUI)
    dxDrawCircle(x+radius, (y+height)-radius, radius, 90, 180, color, color, 16, 1, postGUI)
    dxDrawCircle((x+width)-radius, (y+height)-radius, radius, 0, 90, color, color, 16, 1, postGUI)
    dxDrawCircle((x+width)-radius, y+radius, radius, 270, 360, color, color, 16, 1, postGUI)
    dxDrawRectangle(x, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y+height-radius, width-(radius*2), radius, color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+width-radius, y+radius, radius, height-(radius*2), color, postGUI, subPixelPositioning)
    dxDrawRectangle(x+radius, y, width-(radius*2), radius, color, postGUI, subPixelPositioning)
end